package org.example.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigProperties {
    private static ConfigProperties instance;
    private Properties properties;

    private ConfigProperties() {
        properties = new Properties();
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("config.properties")) {
            if (inputStream == null) {
                throw new RuntimeException("Cannot find config.properties file");
            }
            properties.load(inputStream);
        } catch (IOException e) {
            throw new RuntimeException("Cannot load config.properties file", e);
        }
    }

    public static ConfigProperties getInstance() {
        if (instance == null) {
            synchronized (ConfigProperties.class) {
                if (instance == null) {
                    instance = new ConfigProperties();
                }
            }
        }
        return instance;
    }

    public String getProperty(String key) {
        return properties.getProperty(key);
    }
}
